package com.xmbandu.app.utils;

import android.os.CountDownTimer;
import android.os.Handler;

/**
 * 获取验证码计时器
 */
public class RegisterTimer extends CountDownTimer {
    private static Handler mHandler;
    public static final int IN_RUNNING = 1001;
    public static final int END_RUNNING = 1002;

    /**
     * @param millisInFuture    倒计时的时长
     * @param countDownInterval 间隔时间
     * @param handler           通知进度的Handler
     */
    public RegisterTimer(long millisInFuture, long countDownInterval,
                         Handler handler) {
        super(millisInFuture, countDownInterval);
        mHandler = handler;
    }

    // 结束
    @Override
    public void onFinish() {
        if (mHandler != null)
            mHandler.obtainMessage(END_RUNNING, "").sendToTarget();
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (mHandler != null)
            mHandler.obtainMessage(IN_RUNNING, ""+(millisUntilFinished / 1000) + "秒")
                    .sendToTarget();
    }

    public static void setHandler(Handler handler){
        mHandler=handler;
    }

}
